package cn.crm.system.service.impl;

import cn.crm.common.annotation.DataScope;
import cn.crm.common.utils.SecurityUtils;
import cn.crm.system.domain.pojo.dto.BusinessDto;
import cn.crm.system.domain.pojo.dto.ContactsDto;
import cn.crm.system.domain.pojo.entity.Business;
import cn.crm.system.domain.pojo.vo.BusinessVo;
import cn.crm.system.domain.pojo.vo.ContactsVo;
import cn.crm.system.mapper.BusinessMapper;
import cn.crm.system.mapper.ContactsMapper;
import cn.crm.system.service.IBusinessService;
import cn.crm.system.service.IContactsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.stream.Collectors;


/**
 * 处理联系人的接口
 */

@Slf4j
@Service
public class ContactsServiceImpl implements IContactsService {


    @Autowired
    private ContactsMapper contactsMapper;

    //通过公司id查询出联系人
    @Override
    public List<ContactsVo> selectContactsbyBusinessid(Long businessId) {
        log.debug("开始通过公司id查询出联系人");
        List<ContactsVo> contactsVos = contactsMapper.selectContactsByBusinessId(businessId);
        return contactsVos;
    }
    //删除联系人资料
    @Override
    public int deletecontacts(Long[] id) {
        log.debug("开始删除联系人资料");
        int delcontacts = contactsMapper.delcontacts(id);
        return delcontacts;
    }

    //添加联系人
    @Override
    public int insertContacts(ContactsDto contactsDto) {
        log.debug("开始添加联系人");
        String createAccount = SecurityUtils.getUsername();
        contactsDto.setCreateBy(createAccount);
        int i = contactsMapper.OneInsert(contactsDto);
        return i;
    }

    @Override
    public int updateContacts(ContactsDto contactsDto) {
        log.debug("开心修改联系人资料");
        int i = contactsMapper.updateContactsOne(contactsDto);
        return i ;
    }
}
